package com.study.talk.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

public class MyFragmentPagerAdapter extends FragmentPagerAdapter {


    List<Fragment> fragments;
    String[] title; //加一个用于存储标题的数组或列表

    //使用构造方法将title传过来
    public MyFragmentPagerAdapter(FragmentManager fm, int behavior, List<Fragment> fragments,String[] title) {
        super(fm, behavior);
        this.fragments = fragments;
        this.title = title;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }


    //重写getPageTitle方法 返回值为title[position]
    @Override
    public CharSequence getPageTitle(int position) {
        return title[position];
    }
}
